<?php
define('FPDF_FONTPATH', 'font/');
require('./font/fpdf.php');
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
  $pdf=new FPDF('P','mm','A4');   //Create new pdf file
  $pdf->Open();     //Open file
  $pdf->SetAutoPageBreak(false);  //Disable automatic page break
  $pdf->AddPage();  //Add first page
  
  $i         = 0; 
  $rowHeight = 6;
  $yAxis     = 10;

  $yAxis = $yAxis + $rowHeight;

  //header part start

  function pageHeader()
  {
    global $pdf;
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFillColor(280,0,0);
    $pdf->SetFont('Arial', 'B', 20);
    $pdf->SetXY(25,4);
    $pdf->Cell(62, 8, 'Receiving Challan', 0, 0, 'C', 1);
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 20);
    $pdf->SetXY(5,15);
    $pdf->Cell(113, 6, 'Shakti Heat-Treaters & Engineers', 0, 0, 'R', 0);
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->SetXY(5,21);
    $pdf->Cell(113, 5 , 'Speciallst In All Types Of Heat Treatment Process', 0, 0, 'C', 0);
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->SetXY(5,26);
    $pdf->Cell(113, 5, 'AN ISO 9000:2000 Certified Company', 0, 0, 'C', 0);
    
    
    
    // $pdf->Image('./logo/123.png',5,4,50,18);
    
    $pdf->Image('./logo/logo_21108.gif',154,3,50,18);
    $pdf->Line(5,32,205,32);
  }
  
  function pageHeaderMIddle()
  {
    global $pdf;
    
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->SetXY(5,35);
    $pdf->Cell( 200, 5, 'Sr. No.163/1-p, Plot No.3, S.I.D.C.Road, VERAVAl(SHAPAR), Ta.Kotda Sangani', 0, 0, 'L', 0);
    
   
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->SetXY(5,39);
    $pdf->Cell(200, 5, 'Dist : RajkotTel. :(02827)-252067 Mo. :99740 38980 / 99740 12322', 0, 0, 'L', 0);
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->SetXY(5,43);
    $pdf->Cell(200, 5, 'Email : shaktiheat@gmail.com  -  shaktiheat@yahoo.co.in', 0, 0, 'L', 0);
  
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->SetXY(5,53);
    $pdf->Cell(100, 5, 'Challan No. :',   0, 0, 'L', 0);
    $pdf->Line(30,58,90,58);
    
    $pdf->SetXY(105,53);
    $pdf->Cell(100, 5, 'Party Challan No. :',  0, 0, 'L', 0);
    $pdf->Line(145,58,200,58);
    
    $pdf->SetXY(5,62 );
    $pdf->Cell(100, 5, 'Date :',  0, 0, 'L', 0);
    $pdf->Line(20,66,90,66);
    
    $pdf->SetXY(105,62);
    $pdf->Cell(100, 5, 'Party Challan Date :',  0, 0, 'L', 0);
    $pdf->Line(118,66,200,66);
    
    $pdf->SetXY(5,71);
    $pdf->Cell(200, 5, 'Ms. :',  0 , 0, 'L', 0);
    $pdf->Line(17,76 ,200,76);
    
  }
  
  function pageContain()
  {
    global $pdf;
    global $yAxis;
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->SetXY(5,80);
    $pdf->Cell(15, 6, 'Sr No.',   1, 0, 'C', 0);
    $pdf->Cell(65, 6, 'Grade',   1, 0, 'C', 0);
    $pdf->Cell(40, 6, 'Challan Qty.',  1, 0, 'C', 0);
    $pdf->Cell(40, 6, 'Actual Qty.',   1, 0, 'C', 0);
    $pdf->Cell(40, 6, 'Verified By.', 1, 0, 'C', 0);

    $pdf->Line(5,80,5,$yAxis+94);
    $pdf->Line(205,80,205,$yAxis+94);
    $pdf->Line(5,$yAxis+94,205,$yAxis+94);
    
    $pdf->Line(20,80,20,$yAxis+94);
    $pdf->Line(85,80,85,$yAxis+94);
    $pdf->Line(125,80,125,$yAxis+94);
    $pdf->Line(165,80,165,$yAxis+94);
    
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->SetXY(20,105);
    $pdf->Cell(65,5, '+ Taxes Extra As Applicable', 1, 0, 'L', 0);
  }
  //header part End
  
  pageHeader();
  pageHeaderMIddle();
  pageContain();
  pageFooterlast();
  
  $srNo = 0;
  $srNo++;
  $incomingRegister = array();
	$i =0;
 	$selectincomingRegister = "SELECT incomingId,partyName,DATE_FORMAT(incoming.IncomingDate,'%d-%m-%Y')AS IncomingDate,
                                  	qty,challan,weight,materialName,hardne
	                             FROM incoming
	                             LEFT JOIN party ON party.partyId = incoming.partyId
	                             LEFT JOIN material ON material.materialId = incoming.materialId
	                            WHERE incoming.status = 'planning'
	                              AND incomingId = ".$_REQUEST['incomingId'];
	$selectincomingRegisterRes = mysql_query($selectincomingRegister);
	while($incomingRow = mysql_fetch_array($selectincomingRegisterRes))
	{
		$incomingId   = $incomingRow['incomingId'];
		$partyName    = $incomingRow['partyName'];
		$IncomingDate = $incomingRow['IncomingDate'];
		$qty          = $incomingRow['qty'];
		$challan      = $incomingRow['challan'];
		$weight       = $incomingRow['weight'];
		$material     = $incomingRow['materialName'];
		$hardne       = $incomingRow['hardne'];
		
		$yAxis += $rowHeight;
    $i++;
	}
	 
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 15);
  $pdf->SetXY(33,53);
  $pdf->Cell(58, 5, $incomingId,0,0,'L');
  $pdf->SetXY(145,53);
  $pdf->Cell(55, 5, $challan,0,0,'L');
  $pdf->SetXY(147,61);
  $pdf->Cell(82 ,5, $IncomingDate,0,0,'L');
  $pdf->SetXY(17,70);
  $pdf->Cell(183 ,6, $partyName,0,0,'L');
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', '', 12);
  $pdf->SetXY(5,$yAxis +65);
  $pdf->Cell(15 ,6, $srNo,0,0,'C');
  $pdf->Cell(65 ,6, $material,   0,0,'L');
  $pdf->Cell(40 ,6, $qty,0,0,'C');
  $pdf->Line(124,92,86,92);
  
  $pdf->SetXY(85,$yAxis + 70);
  $pdf->Cell(40 ,6, $weight,0,0,'C');
}

$pdf->Output();  



function pageFooterlast()
{
  global $pdf;
  global $yAxis;
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,$yAxis);
  $pdf->Cell(1, 200, 'Note:', 0, 0, 'L', 0);
  
  $pdf->SetFont('Arial', '', 10);
  $pdf->SetXY(5,$yAxis+6);
  $pdf->Cell(1, 200, ' * The Above Qty.Has Been Verified In Presence Of Your Vehicle Driver/Representative.', 0, 0, 'L', 0);
  $pdf->SetXY(5,$yAxis+12);
  $pdf->Cell(1, 200, ' * Please Verify The Provided Copy Of Receipt At Your End.', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,$yAxis+18);
  $pdf->Cell(1, 200, ' Delivered By.:', 0, 0, 'L', 0);
  $pdf->SetXY(5,$yAxis+24);
  $pdf->Cell(1, 200, ' Mo.:', 0, 0, 'L', 0);
  $pdf->SetXY(5,$yAxis+30);
  $pdf->Cell(1, 200, ' Vehicle No.:', 0, 0, 'L', 0);
  $pdf->SetXY(120,$yAxis+18);
  $pdf->Cell(1, 200, ' Diffi. Informed By.:', 0, 0, 'L', 0);
  $pdf->SetXY(120,$yAxis+30);
  $pdf->Cell(1, 200, ' Diffi. Informed To.:', 0, 0, 'L', 0);
}
?>